const {
    // 新增车位
    addParking,
    // 获取车位数据
    getParkinData,
    // 删除车位
    deleteParking,
    // 获取需要修改车位的数据
    getUpdateParking,
    // 传送修改车位的数据
    postUpdateParking,
    // 修改车位状态数据
    updateParkingState,
    // 查看多个车位审核订单状态
    getTwoParkingState
} = require("../dao/parkingsDao")

// 新增车位

module.exports.addParking = async function (some) {
    const data = await addParking(some)
    // console.log(data, 22222222);
    if (data == undefined) {
        return {
            status: 0,
            message: '添加失败',
        }
    } else {
        return {
            message: '添加成功',
            status: 1,
            data
        }
    }
}
// 获取车位数据

module.exports.getParkinData = async function ({ current, pageSize, value, input, state, lessorsId }) {
    // console.log(current, pageSize, value, input, state);
    if (state == '已审核') {
        const state1 = '2';
        const state2 = '3';
        // console.log(123);
        var { data, totle } = await getTwoParkingState({ current, pageSize, value, input, state1, state2, lessorsId });
        if (totle / pageSize + 1 < current) {
            current = 1;
            var { data, totle } = await getTwoParkingState({ current, pageSize, value, input, state1, state2, lessorsId });
        }
    } else {
        // console.log(321);
        var { data, totle } = await getParkinData({ current, pageSize, value, input, state, lessorsId });
        if (totle / pageSize + 1 < current) {
            current = 1;
            var { data, totle } = await getParkinData({ current, pageSize, value, input, state, lessorsId });
        }
    }
    if (data.length > 0) {
        return {
            message: '获取成功',
            status: 1,
            data,
            totle
        }
    } else {
        return {
            status: 0,
            message: '获取失败',
        }
    }
}

// 删除车位

module.exports.deleteParking = async function (_id) {
    const data = await deleteParking(_id);
    if (data.deletedCount > 0) {
        return {
            message: '删除成功',
            status: 1,

        }
    } else {
        return {
            status: 0,
            message: '删除失败',
        }
    }
}
// 获取需要修改车位的数据

module.exports.getUpdateParking = async function (_id) {
    const data = await getUpdateParking(_id);
    if (data.nModified == 0) {
        return {
            message: '获取成功',
            status: 1,
            data
        }
    } else {
        return {
            status: 0,
            message: '获取失败',
        }
    }
}
// 传送修改车位的数据

module.exports.postUpdateParking = async function (some) {
    const data = await postUpdateParking(some);
    // console.log(data, 222);
    if (data.ok > 0) {
        return {
            message: '修改成功',
            status: 1,
            data
        }
    } else {
        return {
            status: 0,
            message: '修改失败',
        }
    }
}
// 修改车位状态
module.exports.updateParkingState = async function (some) {
    const data = await updateParkingState(some);
    if (data.ok > 0) {
        return {
            message: '修改成功',
            status: 1,
            data
        }
    } else {
        return {
            status: 0,
            message: '修改失败',
        }
    }
}


